package wendyeq.iweb.blog.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import wendyeq.iweb.blog.dao.IArticleDAO;
import wendyeq.iweb.blog.dao.ICommentDAO;
import wendyeq.iweb.blog.dao.impl.ArticleDAO;
import wendyeq.iweb.blog.dao.impl.CommentDAO;
import wendyeq.iweb.blog.pojo.Article;
import wendyeq.iweb.blog.pojo.Comment;
import wendyeq.iweb.blog.pojo.Visitor;
import wendyeq.iweb.blog.service.ICommentService;

@Service("commentServiceImpl")
public class CommentServiceImpl implements ICommentService{
	private static final Logger logger = Logger.getLogger(CommentServiceImpl.class);
	
	@Resource(name="commentDAO")
	private ICommentDAO commentDAO;
	
	@Resource(name="articleDAO")
	private IArticleDAO articleDAO;
	
	/*public Comment insert(String aid, String content, String name, String email,
			String website) {
		logger.warn("aid= " + aid);
		Article article = this.articleDAO.findById(aid);
		logger.warn("artid=  "+article.getId());
		Comment comment = new Comment(article, name, content);
		comment.setEmail(email);
		comment.setWebsite(website);
		return this.commentDAO.insert(comment);
	}
	
	public void updateByVisitor(Comment comment, Visitor visitor) {
		comment.setVisitor(visitor);
		this.commentDAO.update(comment);
	}
	
	public boolean delete(String id){
		this.commentDAO.delete(id);
		return false;
	}
	public Comment findById(String id) {
		return this.commentDAO.findById(id);
	}
	
	public List<Comment> findAll() {
		return this.commentDAO.findAll();
	}
	
	public List<Comment> findByPage(int min, int max) {
		return this.commentDAO.findByPage(min, max);
	}*/

	@Override
	public boolean save(Comment entity) {
		return this.commentDAO.saveOrUpdate(entity);
	}

	@Override
	public boolean delete(String id) {
		return this.commentDAO.delete(id);
	}

	@Override
	public Comment findById(String id) {
		return this.commentDAO.findById(id);
	}

	@Override
	public List<Comment> findByPage(int min, int max) {
		return this.commentDAO.findByPage(min, max);
	}

	@Override
	public List<Comment> findAll() {
		return this.commentDAO.findAll();
	}

}